// StiLib.h: interface for the CStiLib class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_STILIB_H__2E8AB9ED_2A4E_4409_A7AE_FBD2DC27228B__INCLUDED_)
#define AFX_STILIB_H__2E8AB9ED_2A4E_4409_A7AE_FBD2DC27228B__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include <afxtempl.h>
#include "StiFlossTable.h"

#ifndef RED_WEIGHT 
#define RED_WEIGHT 0.299 
#endif 
#ifndef GREEN_WEIGHT 
#define GREEN_WEIGHT 0.587 
#endif 
#ifndef BLUE_WEIGHT 
#define BLUE_WEIGHT 0.114 
#endif

class CStiFlossTable;

class CStiLib : public CObject  
{
public:
	CStiLib(CString name="default", CString desc="");
	virtual ~CStiLib();
	
	CString GetName()
	{
		return m_LibName;
	}
	CString GetDescription()
	{
		return m_Desc;
	}
	CStiFlossTable* GetFlosses()
	{
		return m_pFlosses;
	}
	UINT GetColor(int id);
	void SetColor(int id, UINT clr);

	int MatchFloss(COLORREF color, FLOSS** ppMatch)
	{
		int match = 0;
		POSITION pos = m_pFlosses->GetFlossList()->GetHeadPosition();
		while (pos)
		{
			FLOSS* floss = m_pFlosses->GetFlossList()->GetNext(pos);
			int ret = MatchColor(floss->color, color);
			if (ret > match )
			{
				match = ret;
				*ppMatch = floss;
			}
		}
		return match;
	}

	int ReadFromCol(CString fileName);
	int WritetoCol(CString fileName);
	// read dmc.txt
	int Load(char* fileName);

	void Serialize(CArchive& ar);

protected:
	int MatchColor(COLORREF clr, COLORREF clr2);
	CString m_LibName;
	CString m_Desc;
	CStiFlossTable* m_pFlosses;
	
};

#endif // !defined(AFX_STILIB_H__2E8AB9ED_2A4E_4409_A7AE_FBD2DC27228B__INCLUDED_)
